package net.tv90.bfmccore.command;

import net.tv90.bfmccore.game.GameBase;
import net.tv90.bfmccore.game.GameManager;
import net.tv90.bfmccore.helper.FactionHelper;
import org.bitterorange.flansmodslain.FlansModAPI;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

public class AiCommand implements CommandExecutor {
    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        if (label.equalsIgnoreCase("ai")) {
            if (args.length == 0) {
                sender.sendMessage("/ai add 添加一个ai");
                sender.sendMessage("/ai removeAll 删除所有ai");
                sender.sendMessage("/ai debug");
            }
            else if (args[0].equalsIgnoreCase("add")) {
                if(!(sender instanceof Player)) return false;
                Player p = (Player) sender;
                if(!FactionHelper.getFaction2(p).equals("NoFaction")){
                    FlansModAPI.spawnAI(p.getWorld(), p.getLocation().getBlockX(), p.getLocation().getBlockY(), p.getLocation().getBlockZ(), p);
                }
            }
            else if (args[0].equalsIgnoreCase("removeAll")) {
                for(World world : Bukkit.getWorlds()){
                    FlansModAPI.destroyAllAI(world);
                }
            }
            else if (args[0].equalsIgnoreCase("debug")){
                GameBase game = GameManager.getInstance().currentGame;
                System.out.println("当前游戏最大AI数量" + game.maxAi);
                System.out.println("阵营1当前AI数量" + game.firstFactionCurrentAiNum);
                System.out.println("阵营2当前AI数量" + game.secondFactionCurrentAiNum);
            }
            else {
                sender.sendMessage("未知指令");
            }

            return true;
        }
        return false;
    }
}
